package com.noble.meether.ui.image;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.noble.glamour.module.logic.baseui.custom.TouchImageView;

import java.util.List;

/**
 * PhotoDisplayAct: 大图展示页面
 */
public class PhotoDiaplayAdapter extends FragmentStatePagerAdapter {
    private List<String> imgList;
    private int mCount;

    private PhotoDisplayFragment[] fragments;

    private TouchImageView.OnClickEvent onClickEvent;

    public void setOnClickEvent(TouchImageView.OnClickEvent onClickEvent) {
        this.onClickEvent = onClickEvent;
    }

    public PhotoDiaplayAdapter(FragmentManager fm, List<String> imgList) {
        super(fm);
        this.imgList = imgList;
        this.mCount = imgList.size();

        fragments = new PhotoDisplayFragment[mCount];
    }

    @Override
    public Fragment getItem(int position) {
        if (fragments[position] == null) {
            fragments[position] = new PhotoDisplayFragment();
            Bundle bundle = new Bundle();
            bundle.putString("pic", imgList.get(position));
            fragments[position].setArguments(bundle);
            if (onClickEvent != null) {
                fragments[position].setOnClickEvent(onClickEvent);
            }
        }
        return fragments[position];
    }

    @Override
    public int getCount() {
        return mCount;
    }
}
